import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";
import "rxjs/add/observable/of";
import {ClientNoteModel} from "../../../../model/pages/client/client-note/client-note-edit/client-note.model";

@Injectable()
export class ClientNoteEditProvider {

    constructor(public http: HttpClient) {

    }

    /**
     * 新增笔记
     * @param {ClientNoteModel} clientNoteModel
     * @returns {Observable<any>}
     */
    public saveNote(clientNoteModel: any): Observable<any> {
        return this.http.post("/note/v1", {
            clientId: clientNoteModel.clientNumber,
            content: clientNoteModel.content,
            contentType: clientNoteModel.contentType,
            noteType: clientNoteModel.noteType,
            clientType:clientNoteModel.clientType,
            voiceUrl: clientNoteModel.voiceUrl,
            voiceLength: clientNoteModel.voiceLength
        }, {responseType: "text"});
    }

    /**
     * 修改笔记
     * @param {number} id
     * @param {ClientNoteModel} clientNoteModel
     * @returns {Observable<any>}
     */
    public editNote(id: number, clientNoteModel: ClientNoteModel): Observable<any> {
        return this.http.put(`/note/v1/${id}`, {
            clientId: clientNoteModel.clientNumber,
            content: clientNoteModel.content,
            deliveryType: clientNoteModel.type,
            contentType: clientNoteModel.contentType,
            noteType: clientNoteModel.noteType,
            voiceUrl: clientNoteModel.voiceUrl,
            voiceLength: clientNoteModel.voiceLength
        }, {responseType: "text"});
    }

    /**
     * 删除笔记
     * @param {number} id
     * @returns {Observable<any>}
     */
    public deleteNote(id: number): Observable<any> {
        return this.http.delete(`/note/v1/${id}`, {responseType: "text"});
    }
}
